from google.appengine.ext.webapp import RequestHandler

from os.path import join
from lib.journey import Journey
from google.appengine.ext import db

from lib.webapp import app, render_context, render, MJRequestHandler
import sys

from lib.webapp import app

class ctl_MainPage(MJRequestHandler):
  path = "/"  
  user_required = False
  def index(self):
#    self.response.headers['Content-Type'] = 'text/plain'

    
    #load 50 recently added journeys
    
    self.c.journeys = db.GqlQuery( "select * from Journey where user = :1 order by user, modified desc limit 5", self.user ).fetch(5)
    self.c.journeys += db.GqlQuery( "select * from Journey where user != :1 and public = True  order by user, public, modified desc limit 50", self.user ).fetch(50)

    return self.render("/en/main.html")
    

app().add_handler( "/", ctl_MainPage )
